<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>管理后台</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="./css/font.css">
		<link rel="stylesheet" href="./css/xadmin.css">
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="./js/xadmin.js"></script>
		<script src="js/config.js" type="application/javascript"></script>
		<script src="js/clipboard.min.js"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	</head>

	<body>
		<div class="x-body">
			<form class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">参数选择</label>
					<div class="layui-input-block">
						<select id="params" name="params" lay-filter="params">
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">选择方法</label>
					<div class="layui-input-block">
						<select id="method1" name="method1">
							<options>
								<option value=""></option>
								<option value=".length()">.length() 返回字符串长度（jsonobject的key个数，jsonarray数组元素个数）</option>
								<option value=".replace('被替换的字符串','新字符串')">.replace() 字符串替换</option>
								<option value=".format()">.format() 对日期格式化：如将2019-1-1转换为2019-01-01</option>
							</options>
						</select>
					</div>
					<div class="layui-input-block">
						<select id="method2" name="method2">
							<options>
								<option value=""></option>
								<option value=".length()">.length() 返回字符串长度（jsonobject的key个数，jsonarray数组元素个数）</option>
								<option value=".replace('被替换的字符串','新字符串')">.replace() 字符串替换</option>
								<option value=".format()">.format() 对日期格式化：如将2019-1-1转换为2019-01-01</option>
							</options>
						</select>
					</div>
					<div class="layui-input-block">
						<select id="method3" name="method3">
							<options>
								<option value=""></option>
								<option value=".length()">.length() 返回字符串长度（jsonobject的key个数，jsonarray数组元素个数）</option>
								<option value=".replace('被替换的字符串','新字符串')">.replace() 字符串替换</option>
								<option value=".format()">.format() 对日期格式化：如将2019-1-1转换为2019-01-01</option>
							</options>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="formDemo">确定生成</button>
					</div>
				</div>
				<div id="result">
					<textarea style="padding: 10px; width:95%" id="result1"></textarea>
				</div>
			</form>
		</div>
		<script>
			$("#result").hide()
			layui.use(['layer', 'form'], function() {
				var layer = layui.layer;
				var router = layui.router();
				var form = layui.form;
				$.ajax({
					url: base_url + '/project/sysparam/getlist?page=1&limit=1000',
					contentType: 'application/json; charset=utf-8',
					data: {},
					dataType: 'json',
					async: false,
					success: function(result) {
						if(result.code == '0') {
							var select = document.getElementById("params")
							select.options.add(new Option('result|返回结果', 'result'));
							$.each(result.data, function(n, value) {
								select.options.add(new Option(value.paramname+'|'+value.desc, value.paramname));
							});
							select.options.add(new Option('rand(idcard)|随机身份证号', 'rand(idcard)'));
							select.options.add(new Option('rand(bankid)|随机银行卡号', 'rand(bankid)'));
							select.options.add(new Option('now(date)|当前的日期', 'now(date)'));
							select.options.add(new Option('now(time)|当前时间', 'now(time)'));
							select.options.add(new Option('now(datetime)|当前时间日期', 'now(datetime)'));
							select.options.add(new Option('now(year)|当前年份', 'now(year)'));
							select.options.add(new Option('now(month)|当前月份', 'now(month)'));
							select.options.add(new Option('next(day)|明天', 'next(day)'));
							select.options.add(new Option('next(year)|下个年份', 'next(year)'));
							select.options.add(new Option('next(month)|下个月份', 'next(month)'));
							select.options.add(new Option('rand(orgno)|随机组织机构代码号', 'rand(orgno)'));
							select.options.add(new Option('rand(address)|随机地址', 'rand(address)'));
							select.options.add(new Option('rand(email)|随机邮箱地址', 'rand(email)'));
							select.options.add(new Option('rand(mobile)|随机手机号', 'rand(mobile)'));
							select.options.add(new Option('rand(name)|随机姓名', 'rand(name)'));
							select.options.add(new Option('rand(num)|随机数字', 'rand(num)'));
							
							form.render('select');
						} else {
							layer.msg(result.msg);
						}
					}
				});

				//监听提交
				form.on('submit(formDemo)', function(data) {
					var str = '{$'+$("#params").val();
					if($("#method1").val() != "") {
						str += $("#method1").val();
					}
					if($("#method2").val() != "") {
						str += $("#method2").val();
					}
					if($("#method3").val() != "") {
						str += $("#method3").val();
					}
					var reg = new RegExp("'" , "g" )
					var str = str.replace( reg , "\"")+"}";
					$("#result1").val(str);
					$("#result").show();
					layer.open({
					  type: 1,
					  title: '构造结果',
					  area: ['450px', '100px'],
					  content: $('#result'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
					  end: function () {
					      $("#result").hide()
					  }
					});
					
					return false;
				});
			});
			
		</script>
	</body>

</html>